if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PreservationNoticeHistoryGetBySiteNoticeCustodian]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].PreservationNoticeHistoryGetBySiteNoticeCustodian
GO

CREATE PROCEDURE dbo.PreservationNoticeHistoryGetBySiteNoticeCustodian
(
	@SiteID uniqueidentifier = NULL,
	@PreservationNoticeID int,
	@CustodianID int,
	@NewSiteID uniqueidentifier = NULL
)
AS
SET NOCOUNT ON

IF (@NewSiteID IS NOT NULL)
BEGIN
	SET @SiteID = @NewSiteID
END

SELECT
	PreservationNoticeHistoryID,
	SiteID,
	PreservationNoticeID,
	EventType,
	PreservationNoticeName,
	DateEmailMessageCreated,
	DateEmailMessageSent,
	DateAcknowledged,
	FromAddress,
	MessageSubject, 
	MessageBody,
	Identifier,
	InterviewDate,
	CustodianID,
	CustodianLastName,
	CustodianFirstName,
	HasAttachments,
	CustodianEmail,
	VerificationTries
FROM 
	PreservationNoticeHistory
WHERE
	SiteID = @SiteID AND
	PreservationNoticeID = @PreservationNoticeID AND
	CustodianID = @CustodianID
GO